package com.yuandian.ops.workbench.controller;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.ops.workbench.po.NewestAlarmParams;
import com.yuandian.ops.workbench.service.IRealTimeAlarmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  实时告警Controller
 * <p>
 *
 * @author linshihe
 * @date 2021/10/25
 */
@RestController
@RequestMapping("/ywgzt/newestAlarm")
@Api(tags = "首页二级弹窗页面-Controller")
public class RealTimeAlarmController {

    @Autowired
    private IRealTimeAlarmService realTimeAlarmService;

	/**
     * 二级-首页失败率和响应慢-更多(BPM 4.0)
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-首页失败率和响应慢-更多", notes = "二级-首页失败率和响应慢-更多")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCodeList", 		value = "业务编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "stepCode", 				value = "步骤编码", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "alarmIndicatorCode",  	value = "观察指标类型",		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "dataTypeList", 			value = "数据类型", 			paramType = "query", required = false,  dataType = "List<Integer>"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "pageNum",				 	value = "页码",    			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 				value = "每页大小", 			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getNewestAlarmList")
    public R<Object> getNewestAlarmList(@RequestBody NewestAlarmParams params){
        if (StringUtil.isEmpty(params.getAlarmIndicatorCode())) {
            return R.failed(-1, "指标编码不能为空");
        }

        return R.ok(realTimeAlarmService.getNewestAlarmList(params));
    }

    /**
     * 获取最新告警列表Excel(BPM 4.0)
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-首页失败率和响应慢-更多-下载Excel", notes = "二级-首页失败率和响应慢-更多-下载Excel")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCodeList", 		value = "业务编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "stepCode", 				value = "步骤编码", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "alarmIndicatorCode",  	value = "观察指标类型",		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "dataTypeList", 			value = "数据类型", 			paramType = "query", required = false,  dataType = "List<Integer>"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getNewestAlarmListDownLoad")
    public void getNewestAlarmListDownLoad(@RequestBody NewestAlarmParams params,
                                             HttpServletResponse response) throws IOException {

        realTimeAlarmService.getNewestAlarmListDownLoad(params, response);
    }

    /**
     * 获取告警事件档案总览列表(BPM 4.0)
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-告警事件档案-总览-列表接口", notes = "二级-告警事件档案-总览-列表接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCodeList", 		value = "业务编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "stepCodeList", 			value = "步骤编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "alarmIndicatorCodeList",  value = "观察指标类型",		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "dataTypeList", 			value = "数据类型", 			paramType = "query", required = false,  dataType = "List<Integer>"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "pageNum",				 	value = "页码",    			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 				value = "每页大小", 			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getAlarmEventFileList")
    public R<Object> getAlarmEventFileList(@RequestBody NewestAlarmParams params) {

        return R.ok(realTimeAlarmService.getAlarmEventFileList(params));
    }

    /**
     * 获取告警事件档案详情列表(BPM 4.0)
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-告警事件档案-详情-列表接口", notes = "二级-告警事件档案-详情-列表接口")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCode", 			value = "业务编码", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "stepCode", 				value = "步骤编码", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "alarmIndicatorCode",  	value = "观察指标类型",		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "dataType", 				value = "数据类型", 			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "pageNum",				 	value = "页码",    			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 				value = "每页大小", 			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getAlarmEventFileDetailList")
    public R<Object> getAlarmEventFileDetailList(@RequestBody NewestAlarmParams params) {

        return R.ok(realTimeAlarmService.getAlarmEventFileDetailList(params));
    }

	/**
	 * 首页获取观察区列表(BPM 4.0)
	 *
	 * @param params 请求对象
	 * @return 返回对象
	 */
	@ApiOperation(value = "首页获取观察区列表", notes = "首页获取观察区列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "endTime",   value = "结束时间", paramType = "query", required = true, dataType = "String")
	})
    @PostMapping("/getObservationArealList")
    public R<Object> getObservationArealList(@RequestBody NewestAlarmParams params){
        if (params == null) {
            params = new NewestAlarmParams();
        }
        params.setPageNum(1);
        params.setPageSize(5);
        params.setIsPush(2);
        return R.ok(realTimeAlarmService.getAlarmEventFileDetailList(params));
    }


	/**
     * 获取告警事件档案总览列表Excel(BPM 4.0)
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-告警事件档案-总览-下载Excel", notes = "二级-告警事件档案-总览-下载Excel")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCodeList", 		value = "业务编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "stepCodeList", 			value = "步骤编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "alarmIndicatorCodeList",  value = "观察指标类型",		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "dataTypeList", 			value = "数据类型", 			paramType = "query", required = false,  dataType = "List<Integer>"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getAlarmEventFileListDownLoad")
    public void getAlarmEventFileListDownLoad(@RequestBody NewestAlarmParams params,
                                              HttpServletResponse response) throws IOException {

        realTimeAlarmService.getAlarmEventFileListDownLoad(params, response);
    }

	/**
     * (BPM 4.0)
     * 获取告警事件档案详情列表Excel
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-告警事件档案-详情-列表接口-下载Excel", notes = "二级-告警事件档案-详情-列表接口-下载Excel")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCode", 			value = "业务编码", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "stepCode", 				value = "步骤编码", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "alarmIndicatorCode",  	value = "观察指标类型",		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "dataType", 				value = "数据类型", 			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getAlarmEventFileDetailListDownLoad")
    public void getAlarmEventFileDetailListDownLoad(@RequestBody NewestAlarmParams params,
                                              HttpServletResponse response) throws IOException {

        realTimeAlarmService.getAlarmEventFileDetailListDownLoad(params, response);
    }

	/**
     * (BPM 4.0)
     * 二级-首页右下角最新健康度告警列表-更多
     * @param params 请求参数
     * @return	结果集
     */
	@ApiOperation(value = "二级-首页-右下角-最新健康度告警'更多'列表", notes = "二级-首页-右下角-最新健康度告警'更多'列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCodeList", 		value = "业务编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "stepNameOrCode", 		    value = "步骤名称或编码", 		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "alarmIndicatorCode",  	value = "观察指标类型",		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "dataType", 				value = "数据类型", 			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getHealthAlarmList")
    public R<Object> getHealthAlarmList(@RequestBody NewestAlarmParams params){

        return R.ok(realTimeAlarmService.getHealthAlarmList(params));
    }

	/**
     * (BPM 4.0)
     * 二级-首页右下角最新健康度告警列表Excel-更多
     * @param params 请求参数
     */
	@ApiOperation(value = "二级-首页-右下角-最新健康度告警'更多'-下载Excel", notes = "二级-首页-右下角-最新健康度告警'更多'列表-下载Excel")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 				value = "系统id",  			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "businessCodeList", 		value = "业务编码列表", 		paramType = "query", required = false,  dataType = "List<String>"),
			@ApiImplicitParam(name = "stepNameOrCode", 		    value = "步骤名称或编码", 		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "alarmIndicatorCode",  	value = "观察指标类型",		paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "dataType", 				value = "数据类型", 			paramType = "query", required = false,  dataType = "Integer"),
			@ApiImplicitParam(name = "orderByColumn", 			value = "排序字段", 			paramType = "query", required = false,  dataType = "String"),
			@ApiImplicitParam(name = "isAsc", 					value = "升降序:ASC，DESC",  paramType = "query",  required = false, dataType = "String"),
			@ApiImplicitParam(name = "pageNum",				 	value = "页码",    			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "pageSize", 				value = "每页大小", 			paramType = "query", required = true,   dataType = "Long"),
			@ApiImplicitParam(name = "startTime", 				value = "开始时间", 			paramType = "query", required = true,   dataType = "String"),
			@ApiImplicitParam(name = "endTime", 				value = "结束时间", 			paramType = "query", required = true,   dataType = "String")
	})
    @PostMapping("/getHealthAlarmListDownLoad")
    public void getHealthAlarmListDownLoad(@RequestBody NewestAlarmParams params,
                                                    HttpServletResponse response) throws IOException {

        realTimeAlarmService.getHealthAlarmListDownLoad(params, response);
    }


}
